<?php

/**
 * Description of dayIntervalCreateAction
\* www.teuker.nl - mail@teuker.nl
 * 
 * @author francisc
 */

class dayIntervalCreateAction extends sfAction {

    public function execute($request) {
        $this->form = new DayIntervalForm();

        if ($this->processDayInterval($request, $this->form)) {
            SqlEngineCore::get()->insert(
                    array('table' => 'settings_time_schedule',
                          'columns' => array(
                                'restaurant_id' => array('value' => $this->getUser()->getAttribute('current_restaurant_id'), 'type' => PDO::PARAM_INT),
                                'day' => array('value' => $request->getParameter('day'), 'type' => PDO::PARAM_INT),
                                'time_start' => $this->form->getValue('time_start_hour') . ':' . $this->form->getValue('time_start_minute'),
                                'time_end' => $this->form->getValue('time_end_hour') . ':' . $this->form->getValue('time_end_minute'),
                                'name' => $this->form->getValue('name'),
                                'seats' => $this->form->getValue('seats'))));

            $this->error = 0;
        }
        else {
            $this->error = 1;
        }
    }

    protected function processDayInterval(sfWebRequest $request, sfForm $form) {
        $form->bind($request->getParameter($form->getName()));

        return $form->isValid();
    }
}
